home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / phpmyadmin / querywindow.php < prev    next >
Encoding:
PHP Script  |  2006-11-18  |  13.6 KB  |  383 lines

  1. <?php
  2. /* $Id: querywindow.php 9156 2006-07-03 15:01:45Z cybot_tm $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. require_once('./libraries/common.lib.php');
  6.  
  7. $is_superuser = PMA_isSuperuser();
  8.  
  9. /**
  10.  * Gets the variables sent to this script, retains the db name that may have
  11.  * been defined as startup option and include a core library
  12.  */
  13. if (isset($db) && strlen($db)) {
  14.     $db_start = $db;
  15. }
  16.  
  17.  
  18. /**
  19.  * Gets a core script and starts output buffering work
  20.  */
  21. require_once './libraries/sql_query_form.lib.php';
  22. require_once('./libraries/ob.lib.php');
  23. if ( $GLOBALS['cfg']['OBGzip'] ) {
  24.     $ob_mode = PMA_outBufferModeGet();
  25.     if ( $ob_mode ) {
  26.         PMA_outBufferPre( $ob_mode );
  27.     }
  28. }
  29.  
  30. require_once('./libraries/relation.lib.php');
  31. $cfgRelation = PMA_getRelationsParam();
  32.  
  33.  
  34. // initialize some variables
  35. $_sql_history = array();
  36. $_input_query_history = array();
  37.  
  38. /**
  39.  * Get the list and number of available databases.
  40.  * Skipped if no server selected: in this case no database should be displayed
  41.  * before the user choose among available ones at the welcome screen.
  42.  */
  43. if ($server > 0) {
  44.     PMA_availableDatabases(); // this function is defined in "common.lib.php"
  45. } else {
  46.     $num_dbs = 0;
  47. }
  48.  
  49. // garvin: For re-usability, moved http-headers and stylesheets
  50. // to a seperate file. It can now be included by libraries/header.inc.php,
  51. // querywindow.php.
  52.  
  53. require_once('./libraries/header_http.inc.php');
  54. require_once('./libraries/header_meta_style.inc.php');
  55. ?>
  56. <script type="text/javascript" language="javascript">
  57. //<![CDATA[
  58. function query_auto_commit() {
  59.     document.getElementById( 'sqlqueryform' ).target = window.opener.frame_content.name;
  60.     document.getElementById( 'sqlqueryform' ).submit();
  61.     return;
  62. }
  63.  
  64. function query_tab_commit(tab) {
  65.     document.getElementById('hiddenqueryform').querydisplay_tab.value = tab;
  66.     document.getElementById('hiddenqueryform').submit();
  67.     return false;
  68. }
  69.  
  70. // js form validation stuff
  71. /**/
  72. var errorMsg0   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>';
  73. var errorMsg1   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>';
  74. var noDropDbMsg = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase'])
  75.     ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''; ?>';
  76. var confirmMsg  = '<?php echo $GLOBALS['cfg']['Confirm']
  77.     ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''; ?>';
  78. /**/
  79.  
  80. <?php
  81. if ( empty( $querydisplay_tab ) ) {
  82.     $onload = 'onload="resize();"';
  83. ?>
  84. function resize() {
  85.  
  86.     // for Gecko
  87.     if ( typeof( self.sizeToContent ) == 'function' ) {
  88.         self.sizeToContent();
  89.         //self.scrollbars.visible = false;
  90.         // give some more space ... to prevent 'fli(pp/ck)ing'
  91.         self.resizeBy( 10, 50 );
  92.         return;
  93.     }
  94.  
  95.     // for IE, Opera
  96.     if (document.getElementById && typeof(document.getElementById('querywindowcontainer')) != 'undefined' ) {
  97.  
  98.         // get content size
  99.         var newWidth  = document.getElementById('querywindowcontainer').offsetWidth;
  100.         var newHeight = document.getElementById('querywindowcontainer').offsetHeight;
  101.  
  102.         // set size to contentsize
  103.         // plus some offset for scrollbars, borders, statusbar, menus ...
  104.         self.resizeTo( newWidth + 45, newHeight + 75 );
  105.     }
  106. }
  107. <?php
  108. } else {
  109.     $onload = '';
  110. }
  111. ?>
  112. //]]>
  113. </script>
  114. <script src="./js/functions.js" type="text/javascript" language="javascript"></script>
  115. </head>
  116.  
  117. <body id="bodyquerywindow" <?php echo $onload; ?> >
  118. <div id="querywindowcontainer">
  119. <?php
  120. if ( !isset($no_js) ) {
  121.     $querydisplay_tab = (isset($querydisplay_tab) ? $querydisplay_tab : $GLOBALS['cfg']['QueryWindowDefTab']);
  122.  
  123.     $tabs = array();
  124.     $tabs['sql']['icon']   = 'b_sql.png';
  125.     $tabs['sql']['text']   = $strSQL;
  126.     $tabs['sql']['link']   = '#';
  127.     $tabs['sql']['attr']   = 'onclick="javascript:query_tab_commit(\'sql\');return false;"';
  128.     $tabs['sql']['active'] = (bool) ( $querydisplay_tab == 'sql' );
  129.     $tabs['import']['icon']   = 'b_import.png';
  130.     $tabs['import']['text']   = $strImportFiles;
  131.     $tabs['import']['link']   = '#';
  132.     $tabs['import']['attr']   = 'onclick="javascript:query_tab_commit(\'files\');return false;"';
  133.     $tabs['import']['active'] = (bool) ( $querydisplay_tab == 'files' );
  134.     $tabs['history']['icon']   = 'b_bookmark.png';
  135.     $tabs['history']['text']   = $strQuerySQLHistory;
  136.     $tabs['history']['link']   = '#';
  137.     $tabs['history']['attr']   = 'onclick="javascript:query_tab_commit(\'history\');return false;"';
  138.     $tabs['history']['active'] = (bool) ( $querydisplay_tab == 'history' );
  139.  
  140.     if ( $GLOBALS['cfg']['QueryWindowDefTab'] == 'full' ) {
  141.         $tabs['all']['text']   = $strAll;
  142.         $tabs['all']['link']   = '#';
  143.         $tabs['all']['attr']   = 'onclick="javascript:query_tab_commit(\'full\');return false;"';
  144.         $tabs['all']['active'] = (bool) ( $querydisplay_tab == 'full' );
  145.     }
  146.  
  147.     echo PMA_getTabs( $tabs );
  148.     unset( $tabs );
  149. } else {
  150.     $querydisplay_tab = 'full';
  151. }
  152.  
  153. if ( true == $GLOBALS['cfg']['PropertiesIconic'] ) {
  154.     $titles['Change'] =
  155.          '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
  156.         . 'b_edit.png" alt="' . $strChange . '" title="' . $strChange
  157.         . '" />';
  158.  
  159.     if ( 'both' === $GLOBALS['cfg']['PropertiesIconic'] ) {
  160.         $titles['Change'] .= $strChange;
  161.     }
  162. } else {
  163.     $titles['Change'] = $strChange;
  164. }
  165.  
  166. // Hidden forms and query frame interaction stuff
  167.  
  168. if ( ! empty( $query_history_latest ) && ! empty( $query_history_latest_db ) ) {
  169.     if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) {
  170.         PMA_setHistory((isset($query_history_latest_db) ? $query_history_latest_db : ''),
  171.             (isset($query_history_latest_table) ? $query_history_latest_table : ''),
  172.             $GLOBALS['cfg']['Server']['user'],
  173.             $query_history_latest );
  174.     }
  175.  
  176.     $_input_query_history[$query_history_latest] = array(
  177.         'db'    => $query_history_latest_db,
  178.         'table' => isset($query_history_latest_table) ? $query_history_latest_table : '',
  179.     );
  180.  
  181.     $_sql_history[$query_history_latest] = array(
  182.         'db'    =>  $query_history_latest_db,
  183.         'table' => isset($query_history_latest_table) ? $query_history_latest_table : '',
  184.     );
  185.  
  186.     $sql_query = urldecode($query_history_latest);
  187.     $db = $query_history_latest_db;
  188.     $table = $query_history_latest_table;
  189. } elseif ( ! empty( $query_history_latest ) ) {
  190.     $sql_query = urldecode($query_history_latest);
  191. }
  192.  
  193. if (isset($sql_query)) {
  194.     $show_query = 1;
  195. }
  196.  
  197. if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) {
  198.  
  199.     $temp_history = PMA_getHistory( $GLOBALS['cfg']['Server']['user'] );
  200.     if (is_array($temp_history) && count($temp_history) > 0) {
  201.         foreach ($temp_history AS $history_nr => $history_array) {
  202.             if ( ! isset( $_sql_history[$history_array['sqlquery']] ) ) {
  203.                 $_sql_history[$history_array['sqlquery']] = array(
  204.                     'db'    => $history_array['db'],
  205.                     'table' => isset( $history_array['table'] ) ? $history_array['table'] : '',
  206.                 );
  207.             }
  208.         }
  209.     }
  210.  
  211. } else {
  212.  
  213.     if (isset($query_history) && is_array($query_history)) {
  214.         $current_index = count($query_history);
  215.         foreach ($query_history AS $query_no => $query_sql) {
  216.             if ( ! isset( $_input_query_history[$query_sql] ) ) {
  217.                 $_input_query_history[$query_sql] = array(
  218.                     'db'    => $query_history_db[$query_no],
  219.                     'table' => isset($query_history_table[$query_no]) ? $query_history_table[$query_no] : '',
  220.                 );
  221.                 $_sql_history[$query_sql] = array(
  222.                     'db'    => $query_history_db[$query_no],
  223.                     'table' => isset( $query_history_table[$query_no] ) ? $query_history_table[$query_no] : '',
  224.                 );
  225.             } // end if check if this item exists
  226.         } // end while print history
  227.     } // end if history exists
  228. } // end if DB-based history
  229.  
  230. $url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : '');
  231. if (!isset($goto)) {
  232.     $goto = '';
  233. }
  234.  
  235. require_once './libraries/bookmark.lib.php';
  236.  
  237. if (isset($no_js) && $no_js) {
  238.     // ... we redirect to appropriate query sql page
  239.     // works only full if $db and $table is also stored/grabbed from $_COOKIE
  240.     if ( isset( $table ) && strlen($table) ) {
  241.         require './tbl_properties.php';
  242.     } elseif ( isset($db) && strlen($db) ) {
  243.         require './db_details.php';
  244.     } else {
  245.         require './server_sql.php';
  246.     }
  247.     exit;
  248. }
  249.  
  250. /**
  251.  * Defines the query to be displayed in the query textarea
  252.  */
  253. if ( ! empty( $show_query ) ) {
  254.     $query_to_display = $sql_query;
  255. } else {
  256.     $query_to_display = '';
  257. }
  258. unset( $sql_query );
  259.  
  260. PMA_sqlQueryForm( $query_to_display, $querydisplay_tab );
  261.  
  262. // Hidden forms and query frame interaction stuff
  263. if (isset($auto_commit) && $auto_commit == 'true') {
  264. ?>
  265.         <script type="text/javascript" language="javascript">
  266.         //<![CDATA[
  267.         query_auto_commit();
  268.         //]]>
  269.         </script>
  270. <?php
  271. }
  272.  
  273. if ( count( $_sql_history ) > 0
  274.   && ( $querydisplay_tab == 'history' || $querydisplay_tab == 'full' ) ) {
  275.     $tab = isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full';
  276.     echo $strQuerySQLHistory . ':<br />' . "\n"
  277.         .'<ul>';
  278.     foreach ( $_sql_history as $sql => $query ) {
  279.         echo '<li>' . "\n";
  280.         // edit link
  281.         echo '<a href="#" onclick="'
  282.                .' document.getElementById(\'hiddenqueryform\').'
  283.                .'querydisplay_tab.value = \'' . $tab . '\';'
  284.                .' document.getElementById(\'hiddenqueryform\').'
  285.                .'query_history_latest.value = \''
  286.                 . preg_replace('/(\r|\n)+/i', '\\n',
  287.                     htmlentities( $sql, ENT_QUOTES ) ) . '\';'
  288.                .' document.getElementById(\'hiddenqueryform\').'
  289.                .'auto_commit.value = \'false\';'
  290.                .' document.getElementById(\'hiddenqueryform\').'
  291.                .'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';'
  292.                .' document.getElementById(\'hiddenqueryform\').'
  293.                .'query_history_latest_db.value = \''
  294.                . htmlspecialchars( $query['db'] ) . '\';'
  295.                .' document.getElementById(\'hiddenqueryform\').'
  296.                .'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';'
  297.                .' document.getElementById(\'hiddenqueryform\').'
  298.                .'query_history_latest_table.value = \''
  299.                . htmlspecialchars( $query['table'] ) . '\';'
  300.                .' document.getElementById(\'hiddenqueryform\').submit();'
  301.                .' return false;">' . $titles['Change'] . '</a>';
  302.             // execute link
  303.         echo '<a href="#" onclick="'
  304.                .' document.getElementById(\'hiddenqueryform\').'
  305.                .'querydisplay_tab.value = \'' . $tab . '\';'
  306.                .' document.getElementById(\'hiddenqueryform\').'
  307.                .'query_history_latest.value = \''
  308.                 . preg_replace('/(\r|\n)+/i', '\\r\\n',
  309.                     htmlentities( $sql, ENT_QUOTES ) ) . '\';'
  310.                .' document.getElementById(\'hiddenqueryform\').'
  311.                .'auto_commit.value = \'true\';'
  312.                .' document.getElementById(\'hiddenqueryform\').'
  313.                .'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';'
  314.                .' document.getElementById(\'hiddenqueryform\').'
  315.                .'query_history_latest_db.value = \''
  316.                . htmlspecialchars( $query['db'] ) . '\';'
  317.                .' document.getElementById(\'hiddenqueryform\').'
  318.                .'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';'
  319.                .' document.getElementById(\'hiddenqueryform\').'
  320.                .'query_history_latest_table.value = \''
  321.                . htmlspecialchars( $query['table'] ) . '\';'
  322.                .' document.getElementById(\'hiddenqueryform\').submit();'
  323.                .' return false;">[' . htmlspecialchars( $query['db'] ) . '] '
  324.                . urldecode( $sql ) . '</a>' . "\n";
  325.  
  326.         echo '</li>' . "\n";
  327.     }
  328.     unset( $tab, $_sql_history, $sql, $query );
  329.     echo '</ul>' . "\n";
  330. }
  331. ?>
  332. <form action="querywindow.php" method="post" name="querywindow" id="hiddenqueryform">
  333. <?php
  334. echo PMA_generate_common_hidden_inputs('', '') . "\n";
  335. foreach ( $_input_query_history as $sql => $history ) {
  336.     echo '<input type="hidden" name="query_history[]" value="'
  337.         . $sql . '" />' . "\n";
  338.     echo '<input type="hidden" name="query_history_db[]" value="'
  339.         . htmlspecialchars( $history['db'] ) . '" />' . "\n";
  340.     echo '<input type="hidden" name="query_history_table[]" value="'
  341.         . htmlspecialchars( $history['table'] ) . '" />' . "\n";
  342. }
  343. unset( $_input_query_history, $sql, $history );
  344. ?>
  345.     <input type="hidden" name="db" value="<?php echo (! isset($db) ? '' : htmlspecialchars($db)); ?>" />
  346.     <input type="hidden" name="table" value="<?php echo (! isset($table) ? '' : htmlspecialchars($table)); ?>" />
  347.  
  348.     <input type="hidden" name="query_history_latest" value="" />
  349.     <input type="hidden" name="query_history_latest_db" value="" />
  350.     <input type="hidden" name="query_history_latest_table" value="" />
  351.  
  352.     <input type="hidden" name="previous_db" value="<?php echo htmlspecialchars($db); ?>" />
  353.  
  354.     <input type="hidden" name="auto_commit" value="false" />
  355.     <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
  356. </form>
  357.     <?php
  358. ?>
  359. </div>
  360. </body>
  361. </html>
  362.  
  363. <?php
  364.  
  365. /**
  366.  * Close MySql connections
  367.  */
  368. if (isset($controllink) && $controllink) {
  369.     PMA_DBI_close($controllink);
  370. }
  371. if (isset($userlink) && $userlink) {
  372.     PMA_DBI_close($userlink);
  373. }
  374.  
  375.  
  376. /**
  377.  * Sends bufferized data
  378.  */
  379. if ( $GLOBALS['cfg']['OBGzip'] && isset( $ob_mode ) && $ob_mode ) {
  380.      PMA_outBufferPost($ob_mode);
  381. }
  382. ?>
  383.